package sjtu.rfid.rri.services.device;

import sjtu.rfid.rri.services.queue.Queue;
import sjtu.rfid.rri.services.tag.TagModel;

/**
 * This interface defines the basic operations of a reader
 * 
 * @author Jinghao
 * 
 */
public interface Reader {

	// ////////////////////////////////////////////////
	// // Utility Functions /////
	// ///////////////////////////////////////////////
	/**
	 * get the readerID, it's the primary key of the reader
	 * 
	 * @return
	 */
	public String getReaderID();

	// ////////////////////////////////////////////////
	// ////// Reading Status Control Functions ///////
	// ///////////////////////////////////////////////
	/**
	 * Establish connection to reader and start reading data. It has no effect
	 * if the reading has been started. Put reading into ACTIVE status.
	 * 
	 * @throws ReadingOperationException
	 *             if the operation of device reading control failed to
	 *             complete.
	 */
	public void startReading() throws ReadingOperationException;

	/**
	 * Pause the reader from receiving tags and it has no effect if reader is
	 * not active. Put reading into PAUSED status.
	 * 
	 * @throws ReadingOperationException
	 *             if the operation of device reading control failed to
	 *             complete.
	 */
	public void pauseReading() throws ReadingOperationException;

	/**
	 * Activate the reader to receive tags again and it has no effect if reader
	 * is not paused. Put reader into ACTIVE status.
	 * 
	 * @throws ReadingOperationException
	 *             if the operation of device reading control failed to
	 *             complete.
	 */
	public void resumeReading() throws ReadingOperationException;

	/**
	 * Close reader connection and stop reading data. It has no effect if
	 * reading has been stopped. Put reading into CLOSED status, and CLOSED
	 * status should jump into UNSTARTED status automatically.
	 * 
	 * @throws ReadingOperationException
	 *             if the operation of device reading control failed to
	 *             complete.
	 */
	public void stopReading() throws ReadingOperationException;

	/**
	 * get the status of reading. Either UNSTARTED, ACTIVE , PAUSED or CLOSED.
	 * 
	 * @return the status of reading. Either UNSTARTED, ACTIVE , PAUSED or
	 *         CLOSED.
	 */
	public ReadingStatus getReadingStatus();

	// ////////////////////////////////////////////////
	// // ///////////// Data Functions ///////////////
	// ///////////////////////////////////////////////

	/**
	 * write the information specified by tagModel to the tag.
	 * 
	 * @param operation
	 *            the operation to carry out
	 * @param tagModel
	 *            the tag contents
	 */
	public void operateTag(Operation operation, TagModel tagModel);

	/**
	 * set the out-queue description to the reader
	 * 
	 * @param queueDescription
	 *            the description of out-queue
	 */
	public void setOutQueueDescription(String queueDescription);

	/**
	 * get the out-queue description of the reader
	 * 
	 * @return the description of out-queue
	 */
	public String getOutQueueDescription();

	/**
	 * set the in-queue description to the reader
	 * 
	 * @param queueDescription
	 *            the description of in-queue
	 */
	public void setInQueueDescription(String queueDescription);

	/**
	 * get the in-queue description of the reader
	 * 
	 * @return the description of in-queue
	 */
	public String getInQueueDescription();

	/**
	 * set the out-queue to the reader
	 * 
	 * @param queue
	 *            the in-queue
	 */
	public void setOutQueue(Queue queue);

	/**
	 * get the out-queue of the reader
	 * 
	 * @return the out-queue
	 */
	public Queue getOutQueue();

	/**
	 * set the in-queue to the reader
	 * 
	 * @param queue
	 *            the in-queue
	 */
	public void setInQueue(Queue queue);

	/**
	 * get the in-queue of the reader
	 * 
	 * @return the in-queue
	 */
	public Queue getInQueue();

	/**
	 * @return the readerConfig
	 */
	public ReaderConfig getReaderConfig();

	/**
	 * @param readerConfig
	 *            the readerConfig to set
	 */
	public void setReaderConfig(ReaderConfig readerConfig);

}